<html>
  <head>
    <script type="text/javascript" src="scripts/jquery-1.4.4.js"></script>
    <script type="text/javascript">
    	function addAnsRow() {
        	var ans = $("#ans").val();
        	if (ans == "") {
            	alert("Provide answer");
        	} else {
        		var itype = "radio";
        		var qtype = $("#qtype :selected").html();
        		if (qtype == "MCQ") {
            		var atype = $("#atype :selected").val();
            		if (atype == "Multiple") {
                		itype = "checkbox";
            		}	
        		} 
            		
        		var cell1 = "<td>" + ans + "</td>";
        		var cell2 = "<td><input type=\"" + itype + "\" name= \"" + "answers.answer" + "\" value=\"" + ans + "\"/></td>";
        		var cell3 = "<td><input type=\"text\" size=\"3\" name=\"" + "answers.order" + "\" /></td>";

        		$("#submitbuttonRow").before("<tr>"+cell3+cell1+cell2+"</tr>");  		
        	}	
    	}

    	function qTypeChanged() {
    		var qtype = $("#qtype :selected").html();
    		if (qtype == "Rating") {
    			$("#aTypeTr").hide("fast");
    		} else if (qtype == "MCQ") {
    			$("#aTypeTr").show("fast");
    		}
    	}
    </script>
  </head>
  <body>
  	<form action="saveQ.action" method="post">
  		<table id="questTable">
  			<tr><td>Question</td><td colspan="2"><textArea name="question"></textArea></td></tr>
  			<tr><td>Display</td><td colspan="2"><select name="active"><option value="false">Hide</option><option value="true">Show</option></select></td></tr>
  			<tr><td>Type</td><td colspan="2">
  				<select name="type" id="qtype" onchange="qTypeChanged()">
  					<option>MCQ</option>
  					<option>Rating</option>
  				</select></td>
  			</tr>
  			<tr id="aTypeTr"><td>Answer Type</td><td colspan="2">
  				<select name="answerType" id="atype">
  					<option>Single</option>
  					<option>Multiple</option>
  				</select></td>
  			</tr>
  			<tr><td>Add Answer</td>
  				<td><textarea id="ans"></textarea></td>
  				<td><input type="button" onclick="addAnsRow()" value="Add" /></td>
  			</tr>
  			<tr id="submitbuttonRow"><td colspan="3"><input type="submit" /></td></tr>						
  		</table>	
  	</form>
  </body>
</html> 